package cc.xuanhaojituan.mybatis.config;

import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import tk.mybatis.spring.mapper.MapperScannerConfigurer;

import java.util.Properties;

@Configuration
// TODO 注意，由于MapperScannerConfigurer执行的比较早，所以必须有下面的注解
@AutoConfigureAfter(SessionFactoryConfig.class)
public class MyBatisMapperScannerConfig {

	@Bean
	public MapperScannerConfigurer mapperScannerConfigurer() {
		MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
		mapperScannerConfigurer.setBasePackage("com.nuanxin.order.mapper");
		Properties propertiesMapper = new Properties();
		// 通用mapper位置，不要和其他mapper、dao放在同一个目录
		propertiesMapper.setProperty("mappers", "com.nuanxin.order.util.GenericMapper");
		propertiesMapper.setProperty("notEmpty", "false");
		// 主键UUID回写方法执行顺序,默认AFTER,可选值为(BEFORE|AFTER)
		propertiesMapper.setProperty("ORDER", "BEFORE");
		propertiesMapper.setProperty("IDENTITY", "MYSQL");
		mapperScannerConfigurer.setProperties(propertiesMapper);
		return mapperScannerConfigurer;
	}

}
